package uit.ce03.game_ninja.player;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.util.path.astar.AStarPathFinder;

import uit.ce03.game_ninja.map.MyMap;

import android.content.Context;



public class Player  {
	//cac bien dinh danh
	
	//------------------------------------------------------------------------------------------
	private int mStatus_player = Status_player.MOVE_RIGHT;
	//------------------------------------------------------------------------------------------
	private int heart =3;
	private float positionX = 0;
	private float positionY = 0;
	private TiledTextureRegion player1_TlieTextureRegion;
	private BitmapTextureAtlas player1_bitmapAtlas;
	public AnimatedSprite player1_animatedSprite;
	private AStarPathFinder<AnimatedSprite> finder;
	
	
	public Player() {
		
	}
	public void onLoadResources(Engine mEngine,Context mContext)
	{
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("player/");
		player1_bitmapAtlas = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		player1_TlieTextureRegion = new BitmapTextureAtlasTextureRegionFactory().createTiledFromAsset(player1_bitmapAtlas, mContext,
										"player.png", 0, 0, 5, 3);
		mEngine.getTextureManager().loadTexture(player1_bitmapAtlas);
	
	}
	public void setChuyendongMap(Camera mCamera,MyMap mMap)
	{
		finder = new AStarPathFinder<AnimatedSprite>(mMap, 10, true);
		mCamera.setChaseEntity(player1_animatedSprite);
	}
	public void onLoadScene(Scene mScene)
	{
		
		player1_animatedSprite = new AnimatedSprite(positionX, positionY, player1_TlieTextureRegion);
		mScene.attachChild(player1_animatedSprite);
	}
	public float getPositionX() {
		return positionX;
	}
	public void setPositionX(float positionX) {
		this.positionX = positionX;
	}
	public float getPositionY() {
		return positionY;
	}
	public void setPositionY(float positionY) {
		this.positionY = positionY;
	}
	public void setPositionXY(float positionX, float positionY) {
		
		this.positionX = positionX;
		this.positionY = positionY;
	}
	public int getStatus_player() {
		return mStatus_player;
	}
	public void setStatus_player(int status_player) {
		mStatus_player = status_player;
		ShowStatusPlayer();
	}
	void ShowStatusPlayer()
	{
		switch(this.mStatus_player)
		{
			case Status_player.MOVE_LEFT:
			{
				player1_animatedSprite.animate(new long[]{100,100,100},new int[]{7,8,9} , 1000);
				break;
			}
			case Status_player.MOVE_RIGHT :
			{
				player1_animatedSprite.animate(new long[]{100,100,100},new int[]{2,3,4} , 1000);
				break;
			}
			case Status_player.UN_MOVE_LEFT :
			{
				player1_animatedSprite.animate(new long[]{100,100},new int[]{12,12} , 2);
				break;
			}
			case Status_player.UN_MOVE_RIGHT :
			{
				player1_animatedSprite.animate(new long[]{100,100},new int[]{10,10} , 2);
				break;
			}
			case Status_player.CHEM_TRAI:
			{
				player1_animatedSprite.animate(new long[]{1000},new int[]{1} , 1000);
				break;
			}
			case Status_player.CHEM_PHAI:
			{
				player1_animatedSprite.animate(new long[]{1000},new int[]{6} , 1000);
				break;
			}
			
		}
	}
	public void MovePlayer()
	{
		player1_animatedSprite.setPosition(positionX, positionY);
	}
	public void MoveX(float movex)
	{
		positionX = movex;
		MovePlayer();
	}
	public void MoveY(float moveY)
	{
		positionY = moveY;
		MovePlayer();
	}
	public void MoveXY(float moveX, float moveY)
	{
		positionX = moveX;
		positionY= moveY;
		MovePlayer();
	}
	public void MoveLienTucX(float x)
	{
		positionX += x;
		MovePlayer();
	}
	public void MoveLienTucY(float y)
	{
		positionY += y;
		MovePlayer();
	}
	public void MoveLienTucXY(float x, float y)
	{
		positionX += x;
		positionY +=y;
		MovePlayer();
	}
	public int getHeart() {
		return heart;
	}
	public void setHeart(int heart) {
		this.heart = heart;
	}
	public AnimatedSprite getAnimatedSprite()
	{
		return player1_animatedSprite;
		
	}
	
	
	
}
